package com.swust.reactredis.normal;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.time.temporal.ChronoUnit;

/**
 * @author: Chen Yixing
 * @since: 2024/4/28 08:01:08
 * @description:
 */
@Slf4j
@Component
public class NormalApplicationRunner implements ApplicationRunner {
    @Autowired
    NormalUsage templateUsage;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        //有效期设置为60秒
        templateUsage.setValue("name", "8848", 60, ChronoUnit.SECONDS);
        Mono<String> nameMono = templateUsage.getValue("joke");
        nameMono.subscribe(name -> log.info("name = {}", name));

        templateUsage.getNodeInfo().subscribe(info -> System.out.println(JSON.toJSONString(info)));
    }
}
